package com.youbug.mall.product_pms.service.impl;

import com.youbug.mall.product_pms.entity.PmsSpuInfoDesc;
import com.youbug.mall.product_pms.mapper.PmsSpuInfoDescMapper;
import com.youbug.mall.product_pms.service.IPmsSpuInfoDescService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import com.youbug.common.vo.QueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.util.StringUtils;

/**
 * <p>
 * spu信息介绍 服务实现类
 * </p>
 *
 * @author youbug
 * @since 2024-04-21
 */
@Service
public class PmsSpuInfoDescServiceImpl extends ServiceImpl<PmsSpuInfoDescMapper, PmsSpuInfoDesc> implements IPmsSpuInfoDescService {

        @Override
        public IPage<PmsSpuInfoDesc> getPmsSpuInfoDescPage(QueryVo<PmsSpuInfoDesc> queryVo) {

        Page<PmsSpuInfoDesc> paramPage = new Page<>();

        paramPage.setCurrent(queryVo.getCurrentPage());

        paramPage.setSize(queryVo.getPageSize());

        QueryWrapper<PmsSpuInfoDesc> wrapper = new QueryWrapper<>();

        PmsSpuInfoDesc pmsSpuInfoDesc = queryVo.getPayload();

        if(!ObjectUtils.isEmpty(pmsSpuInfoDesc)){
            if(StringUtils.hasText(pmsSpuInfoDesc.getDecript())){
                wrapper.eq("decript", pmsSpuInfoDesc.getDecript());
            }
        }
        if(!ObjectUtils.isEmpty(queryVo.getStartTime())){
            wrapper.gt("create_time", queryVo.getStartTime());
        }
        if(!ObjectUtils.isEmpty(queryVo.getEndTime())){
            wrapper.lt("create_time", queryVo.getEndTime());
        }
        wrapper.orderByDesc("create_time");

        Page<PmsSpuInfoDesc> page = this.page(paramPage, wrapper);

        return page;
        }

}
